package com.data.service.manage.impl;

import com.data.domain.manage.Acctbindlist;
import com.data.domain.manage.AcctbindlistCriteria;
import com.data.mapper.manage.AcctbindlistMapper;
import com.data.mapper.report.AreainfoMapper;
import com.data.model.ManagerModel;
import com.data.service.manage.AcctbindlistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;

@Service(value = "acctbindlistService")
public class AcctbindlistServiceImpl implements AcctbindlistService {

    @Autowired
    private AcctbindlistMapper acctbindlistMapper;

    @Autowired
    private AreainfoMapper areainfoMapper;

    /**
     * 账户绑定流水表查询
     * @param managerModel
     * @return
     */

    @Override
    public List<Acctbindlist> getAcctbindlist(ManagerModel managerModel){
        AcctbindlistCriteria acctbindlistCriteria=new AcctbindlistCriteria();
        AcctbindlistCriteria.Criteria criteria=acctbindlistCriteria.createCriteria();
//        if(StringUtils.isNoNullString(managerModel.getStart())){
//            criteria.andCreatedateGreaterThan(StringUtils.cutDateStr(managerModel.getStart()));
//        }
//        if(StringUtils.isNoNullString(managerModel.getEnd())){
//            criteria.andCreatedateLessThan(StringUtils.cutDateStr(managerModel.getEnd()));
//        }
//        if(StringUtils.isNoNullString(managerModel.getCode())){
//            criteria.andOrgcodeEqualTo(managerModel.getCode());
//        }
//        if(managerModel.getAreacode().equals("3300")&& StringUtils.isNoNullString(managerModel.getAreaname())){
//            criteria.andAreacodeEqualTo(StringUtils.getIdFromString(managerModel.getAreaname()));
//        }
//        if (null!=managerModel.getAreacode() && !managerModel.getAreacode().equals("3300")){
//            criteria.andAreacodeEqualTo(managerModel.getAreacode());
//        }
//        if(StringUtils.isNoNullString(managerModel.getOrgname())){
//            criteria.andOrgnameEqualTo(managerModel.getOrgname());
//        }
        acctbindlistCriteria.setOrderByClause("id asc");
        List<Acctbindlist> data = acctbindlistMapper.selectByExample(acctbindlistCriteria);
//        for (Acctbindlist acctbindlist:acctbindlistMapper.selectByExample(acctbindlistCriteria)){
//            AreainfoCriteria areainfoCriteria = new AreainfoCriteria();
//            areainfoCriteria.createCriteria().andCodeEqualTo(acctbindlist.getAreacode());
//            List<Areainfo> areas = areainfoMapper.selectByExample(areainfoCriteria);
//            if (areas!=null&&areas.size()>0) {
//                acctbindlist.setAreacode(areainfoMapper.selectByExample(areainfoCriteria).get(0).getName());
//            }
//            data.add(acctbindlist);
//        }
        return data;
    }

    /**
     * 账户绑定流水表插入
     * @param managerModel
     * @return
     */
    @Override
    public int insertAcctbindlist(ManagerModel managerModel){
        AcctbindlistCriteria acctbindlistCriteria=new AcctbindlistCriteria();
        Acctbindlist data = new Acctbindlist();
//        data.setId(Integer.parseInt(managerModel.getId()));
        data.setWorkdate(managerModel.getWorkdate());
        data.setSender(managerModel.getSender());
        data.setRecver(managerModel.getRecver());
        data.setSendrefid(managerModel.getSendrefid());
        data.setMngtype(managerModel.getMngtype());
        data.setAgtorder(managerModel.getAgtorder());
        data.setAgtid(managerModel.getAgtid());
        data.setOrgcode(managerModel.getOrgcode());
        data.setPrtry(managerModel.getPrtry());
        data.setIdtype(managerModel.getIdtype());
        data.setIdcode(managerModel.getIdcode());
        data.setPhone(managerModel.getPhone());
//        data.setAcctbank(managerModel.getAcctbank());
//        data.setAccount(managerModel.getAccount());
//        data.setAcctname(managerModel.getAcctname());
//        data.setAcctclass(Short.parseShort(managerModel.getAcctclass()));
//        data.setBindacctbank(managerModel.getBindacctbank());
//        data.setBindacct(managerModel.getBindacct());
//        data.setBindname(managerModel.getBindname());
        data.setEffectdate(managerModel.getEffectdate());
        data.setSysecode(managerModel.getSysecode());
        data.setErrcode(managerModel.getErrcode());
        data.setErrinf(managerModel.getErrinf());
        data.setRegistertime(new Date());//根据需要修改
        return acctbindlistMapper.insertSelective(data);
    }

    /**
     * 账户绑定流水表修改
     * @param managerModel
     * @return
     */
    @Override
    public int modifyAcctbindlist(ManagerModel managerModel ,int id) {
        AcctbindlistCriteria acctbindlistCriteria=new AcctbindlistCriteria();
        acctbindlistCriteria.createCriteria().andIdEqualTo(id);
        Acctbindlist data = new Acctbindlist();
        data.setWorkdate(managerModel.getWorkdate());
        data.setSender(managerModel.getSender());
        data.setRecver(managerModel.getRecver());
        data.setSendrefid(managerModel.getSendrefid());
        data.setMngtype(managerModel.getMngtype());
        data.setAgtorder(managerModel.getAgtorder());
        data.setAgtid(managerModel.getAgtid());
        data.setOrgcode(managerModel.getOrgcode());
        data.setPrtry(managerModel.getPrtry());
        data.setIdtype(managerModel.getIdtype());
        data.setIdcode(managerModel.getIdcode());
        data.setPhone(managerModel.getPhone());
//        data.setAcctbank(managerModel.getAcctbank());
//        data.setAccount(managerModel.getAccount());
//        data.setAcctname(managerModel.getAcctname());
//        data.setAcctclass(Short.parseShort(managerModel.getAcctclass()));
//        data.setBindacctbank(managerModel.getBindacctbank());
//        data.setBindacct(managerModel.getBindacct());
//        data.setBindname(managerModel.getBindname());
        data.setEffectdate(managerModel.getEffectdate());
        data.setSysecode(managerModel.getSysecode());
        data.setErrcode(managerModel.getErrcode());
        data.setErrinf(managerModel.getErrinf());
        data.setRegistertime(new Date());//根据需要修改
        return acctbindlistMapper.updateByExampleSelective(data,acctbindlistCriteria);
    }

}
